package com.atlin.project.model.vo;


import cn.hutool.json.JSONUtil;
import com.atlin.project.model.domain.Notification;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 通知信息
 *
 * @TableName notification
 */
@Data
public class NotificationVO implements Serializable {
    /**
     * id
     */
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 开始时间
     */
    private Date startTime;

    /**
     * 结束时间
     */
    private Date endTime;

    /**
     * 所属用户
     */
    private String userId;

    /**
     * 0：关闭，1：启用
     */
    private Integer status;

    /**
     * 域名
     */
    private List<String> domain;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 包装类转换为实体
     *
     * @param notificationVO 包装类
     * @return 实体类
     */
    public static Notification voToObj(NotificationVO notificationVO) {
        if (notificationVO == null) {
            return null;
        }
        Notification notification = new Notification();
        BeanUtils.copyProperties(notificationVO, notification);
        List<String> domainList = notificationVO.getDomain();
        if (domainList != null) {
            notification.setDomain(JSONUtil.toJsonStr(domainList));
        }

        return notification;
    }

    /**
     * 对象转包装类
     *
     * @param notification
     * @return
     */
    public static NotificationVO objToVo(Notification notification) {
        if (notification == null) {
            return null;
        }
        NotificationVO notificationVO = new NotificationVO();
        BeanUtils.copyProperties(notification, notificationVO);
        List<String> domianList = JSONUtil.toList(notification.getDomain(), String.class);
        notificationVO.setDomain(domianList);
        return notificationVO;
    }

    private static final long serialVersionUID = 1L;
}